package xyz.eden.cloud.common.mybatis.support.fill.annotation.enums;


import xyz.eden.cloud.common.core.enums.IEnum;
import xyz.eden.cloud.common.core.util.LocalDatetimeUtils;

import java.util.Date;
import java.util.Objects;

/**
 * Date 类型
 */
public enum DateType implements IEnum {

    /**
     * Long 类型
     */
    LONG,
    /**
     * LocalDateTime
     */
    LOCAL_DATE_TIME,
    /**
     * Date
     */
    DATE;

    public static Object getDateVal(DateType dateType, Long currentTime) {
        Long cTime = Objects.isNull(currentTime) ? System.currentTimeMillis() : currentTime;
        Object obj = null;
        switch (dateType) {
            case LONG: {
                obj = cTime;
                break;
            }
            case LOCAL_DATE_TIME: {
                obj = LocalDatetimeUtils.toLocalDateTime(cTime);
                break;
            }
            case DATE: {
                obj = new Date(cTime);
                break;
            }
            default: {
                return null;
            }
        }
        return obj;
    }
}
